<!DOCTYPE html . "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
	<title></title>
	<script type="text/javascript" src="Public/uploadify/jquery-1.8.2.min.js"></script>
	<!--载入编辑器-->
	<script type="text/javascript" charset="utf-8" src="Public/ueditor1_4_3/ueditor.config.js"></script>
    <script type="text/javascript" charset="utf-8" src="Public/ueditor1_4_3/ueditor.all.min.js"> </script>
    <script type="text/javascript" charset="utf-8" src="Public/ueditor1_4_3/lang/zh-cn/zh-cn.js"></script>
	<!--载入uploadify相关文件-->
	<script type="text/javascript" src="Public/uploadify/jquery.uploadify.min.js"></script>
	<link href="Public/uploadify/uploadify.css" type="text/css" rel="stylesheet"></link>
	<!--载入hdjs-->
	<link rel="stylesheet" type="text/css" href="Public/hdjs/hdjs.css"/>
    <script src="Public/hdjs/hdjs.min.js" type="text/javascript" charset="utf-8"></script>
    <style type="text/css">
		li{
			list-style: none;
			float: right;
		}
		tr{
			height: 30px;
		}
		input{
			height: 20px;
			font-size: 14px;
		}
	</style>
</head>
<body>
	
	<div class="container-fluid">
	<div class="row-fluid">
	<div class="span12">
	<form action="" method='post' enctype="multipart/form-data" id="add_goods">			
			<h2 class="hd-title-header">添加商品</h2>
			<table class='hd-table hd-table-form' style="border-top:1px solid #E5E5E5 ;">	
			<p class="hd-title-header">基本信息</p>			
			<script type="text/javascript">
				$(function(){
					$("select[name=cate_cid]").change(function(){
						var lid = $(":selected").attr('oftype_lid');
//						alert(lid)
						$.ajax({
							type:"post",
							url:"{{U('addajax')}}",
							data:{lid:lid},
							dataType:"json",
							success:function(data){
								var attr = "";
								var spec = "";
								$.each(data, function(k,v) {
									if(v.class == 1)
									{
										attr += '<tr><td>'+v.xname+'</td><td><select name="attr['+v.xid+']"><option value="0">-请选择-</option>';
										$.each(v.xvalue, function(kk,vv) {
											attr += '<option value="'+vv+'">'+ vv +'</option>';
										});
										attr += '</td></tr>';
									}else{
										spec += '<tr><td>'+v.xname+'</td><td><select name="spec['+v.xid+'][color][]"><option value="0">-请选择-</option>';
										$.each(v.xvalue, function(kk,vv) {
											spec += '<option value="'+vv+'">'+ vv +'</option>';
										});
										spec += '</td><td>附加价格</td><td><input type="text" name="spec['+v.xid+'][added][]" value="0"/><a href="javascript:;" class="tianjia">添加</a></td></tr>';
									}
								});
								$("#attr").html(attr);
								$("#spec").html(spec);
							}
						});
					})
				})
			</script>
			<script type="text/javascript">
				$(function(){
					$(".tianjia").live("click",function(){
						var rt = $(this).parents('tr').clone();
						$(this).parents('tr').after(rt);
						rt.find(".tianjia").remove();
						var del = '<a href="javascript:;" class="del">删除</a>';
						rt.find("td").eq(3).append(del);
					})
					$(".del").live("click",function(){
						$(this).parents("tr").remove();
					})
				})
			</script>
						<script type="text/javascript">
			                $(function() {
			                    $('#file1').uploadify({
			                        'formData'     : {//POST数据
			                            '<?php echo session_name();?>' : '<?php echo session_id();?>',
			                        },
			                        'fileTypeDesc' : '上传文件',//上传描述
			                        'fileTypeExts' : '*.jpg;*.png',
			                        'swf'      : '{{__PUBLIC__}}/uploadify/uploadify.swf',
			                        'uploader' : "{{U('ajaxUpload')}}",
			                        'buttonText':'选择文件',
			                        'fileSizeLimit' : '2000KB',
			                        'uploadLimit' : 1000,//上传文件数
			                        'width':65,
			                        'height':25,
			                        'successTimeout':10,//等待服务器响应时间
			                        'removeTimeout' : 0.2,//成功显示时间
			                        'onUploadSuccess' : function(file, data, response) {
//			                        	console.log(data);
			                            data=$.parseJSON(data);
			                            var imageUrl = data.image?data.url:'{{__PUBLIC__}}/image/default.png';
			                            var li="<li path='"+data.path+"' url='"+data.url+"'><img src='"+imageUrl+"' class='hd-w80 hd-h70'/><a href='javascript:;' style='color:red' class='del-image'>X</a>";
			                            li +='<input type="hidden" name="thumb" value="'+data.path+'"/>';
			                            li +='</li>';
			                            $("#photo-list").prepend(li);
			                        }
			                    });
			                });
			             </script>
			             <script type="text/javascript">
			             	$(function(){
			             		$(".del-image").live("click",function(){
			             			var li = $(this).parents("li");
			             			var path = li.attr("path");
			             			li.remove();
			             			$.ajax({
			             				type:"post",
			             				url:"{{U('delimg')}}",
			             				data:{path:path},
			             				dataType:"json",
			             				success:function(data){
			             					if(data==1){
			             						li.remove();
			             					}
			             				}
			             			});
			             		})
			             	})
			             </script>
			             <script type="text/javascript">
			                $(function() {
			                    $('#file2').uploadify({
			                        'formData'     : {//POST数据
			                            '<?php echo session_name();?>' : '<?php echo session_id();?>',
			                        },
			                        'fileTypeDesc' : '上传文件',//上传描述
			                        'fileTypeExts' : '*.jpg;*.png',
			                        'swf'      : '{{__PUBLIC__}}/uploadify/uploadify.swf',
			                        'uploader' : "{{U('ajaxUpload')}}",
			                        'buttonText':'选择文件',
			                        'fileSizeLimit' : '2000KB',
			                        'uploadLimit' : 1000,//上传文件数
			                        'width':65,
			                        'height':25,
			                        'successTimeout':10,//等待服务器响应时间
			                        'removeTimeout' : 0.2,//成功显示时间
			                        'onUploadSuccess' : function(file, data, response) {
			                        	//console.log(data);
			                            data=$.parseJSON(data);
			                            var imageUrl = data.image?data.url:'{{__PUBLIC__}}/image/default.png';
			                            var li="<li path='"+data.path+"' url='"+data.url+"'><img src='"+imageUrl+"' class='hd-w80 hd-h70'/><a href='javascript:;' style='color:red' class='del-image'>X</a>";
			                            li +='<input type="hidden" name="smb[]" value="'+data.path+'"/>';
			                            li +='</li>';
			                            $("#photo-one").prepend(li);
			                        }
			                    });
			                });
			             </script>
			             <script type="text/javascript">
			             	$(function(){
			             		$(".del-image").live("click",function(){
			             			var li = $(this).parents("li");
			             			var path = li.attr("path");
//			             					alert(path);
									li.remove();
			             			$.ajax({
			             				type:"post",
			             				url:"{{U('delimg')}}",
			             				data:{path:path},
			             				dataType:"json",
			             				success:function(data){
			             					if(data==1){
			             						li.remove();
			             					}
			             				}
			             			});
			             		})
			             	})
			             </script>
				<tbody>
					<tr class="info">
						<td>所属分类</td>
						<td>
							<select name="cate_cid">
								<option value="0" oftype_lid="0">-请选择-</option>
									{{foreach from='$CateData' key='$k' value='$v'}}
									<option value="{{$v['cid']}}" oftype_lid="{{$v['oftype_lid']}}" {{if value="$v['cid']==$OldData['cate_cid']"}}selected{{endif}}>{{$v['_cname']}}</option>
									{{endforeach}}					
							</select>
						</td>
					</tr>
					<tr class="info">
						<td>所属品牌</td>
						<td>
							<select name="brand_pid">
								<option value="0">-请选择-</option>
									{{foreach from='$BrandData' key='$k' value='$v'}}
									<option value="{{$v['pid']}}" {{if value="$v['pid']==$OldData['brand_pid']"}}selected{{endif}}>{{$v['pname']}}</option>
									{{endforeach}}
							</select>

						</td>
					</tr>
					<tr class="info">
						<td>商品名称</td>
						<td>
							<input type="text" name='sname' value="{{$OldData['sname']}}" style="width: 400px;"/>
						</td>
					</tr>
					<tr class="info">
						<td>商品货号</td>
						<td>
							<input type="text" name='artno' value="{{$OldData['grounding']}}"/>
						</td>
					</tr>
					<tr class="info">
						<td>单位</td>
						<td>
							<input type="text" name='unit' value="{{$OldData['unit']}}"/>
						</td>
					</tr>
					<tr class="info">
						<td>市价场</td>
						<td>
							<input type="text" name='market'value="{{$OldData['market']}}"/>
						</td>
					</tr>
					<tr class="info">
						<td>商城价</td>
						<td>
							<input type="text" name='sale' value="{{$OldData['sale']}}"/>
						</td>
					</tr>
					<tr class="info">
						<td>点击次数</td>
						<td>
							<input type="text" name='click' value="{{$OldData['click']}}"/>
						</td>
					</tr>
					<tr class="info">
						<td>库存</td>
						<td>
							<input type="text" name='stock' value="{{$OldData['zongku']}}"/>
						</td>
					</tr>
				</tbody>
			</table>

			<p class="hd-title-header">商品属性</p>
			<table class="hd-table hd-table-form" id='attr' style="border-top:1px solid #E5E5E5 ;">
				{{foreach from='$TypeattrData' key='$k' value='$v'}}
				{{if value="$v['class']=='1'"}}
				<tr class="info">
						<td>{{$v['xname']}}</td>
						<td>
							<select name="attr[{{$v['xid']}}]">
								<option value="0" oftype_lid="0">-请选择-</option>
									{{foreach from="$v['xvalue']" key='$ke' value='$va'}}
									<option value="{{$va}}" {{if value="$va==$v['shopvalue']"}}selected{{endif}}>{{$va}}</option>
									{{endforeach}}					
							</select>
						</td>
					</tr>
				{{endif}}
				{{endforeach}}
			</table>
			<p class="hd-title-header">商品规格</p>
			<table class="hd-table hd-table-form" id='spec' style="border-top:1px solid #E5E5E5 ;">
				{{foreach from='$TypeattrData' key='$k' value='$v'}}
				{{if value="$v['class']=='0'"}}
				<tr class="info">
						<td>{{$v['xname']}}</td>
						<td>
							<select name="spec[{{$v['xid']}}][color][]">
								<option value="0" oftype_lid="0">-请选择-</option>
									{{foreach from="$v['xvalue']" key='$ke' value='$va'}}
									<option value="{{$va}}" {{if value="$va==$v['shopvalue']"}}selected{{endif}}>{{$va}}</option>
									{{endforeach}}					
							</select>
						</td>
						<td>附加价格</td>
						<td>
							<input type="text" name="spec[{{$v['xid']}}][added][]" value="{{$v['addition']}}"/>
							<a href="javascript:;" class="tianjia">添加</a>
						</td>
					</tr>
				{{endif}}
				{{endforeach}}
			</table>
			
			<p class="hd-title-header">列表图</p>
			<table class='hd-table hd-table-form' style="border-top:1px solid #E5E5E5 ;">
				
				<tr class="info">
					<td>上传图片</td>
					<td>
						<input id="file1" type="file" multiple="true" name="photos"/>
	            		<span>类型: *.jpg,*.png 大小: 2000KB 数量: 10</span>
					</td>
					<td id='photo-list'>
						
						<li path="{{$OldData['thumb']}}" url="{{$OldData['thumb']}}"><img src="{{$OldData['thumb']}}" class="hd-w80 hd-h70"/><a href='javascript:;' style='color:red' class='del-image'>X</a>
			            <input type="hidden" name="thumb" value="{{$OldData['thumb']}}"/>
			            
			            </li>
					</td>
				</tr>
			</table>
			<p class="hd-title-header">商品图册</p>
			<table class='hd-table hd-table-form' style="border-top:1px solid #E5E5E5 ;">
				<tr class="info">
					<td>上传图片</td>
					<td>
						<input id="file2" type="file" multiple="true" name="photos"/>
	            		<span>类型: *.jpg,*.png 大小: 2000KB 数量: 10</span>
					</td>
					
					<td id='photo-one'>
						{{foreach from="$OlddetailsData['big']" key='$k' value='$v'}}
						<li path="{{$v}}" url="{{$v}}"><img src="{{$v}}" class="hd-w80 hd-h70"/><a href='javascript:;' style='color:red' class='del-image'>X大图</a>
			            <input type="hidden" name="smb[]" value="{{$v}}"/>
			            {{endforeach}}
			            {{foreach from="$OlddetailsData['mean']" key='$k' value='$v'}}
						<li path="{{$v}}" url="{{$v}}"><img src="{{$v}}" class="hd-w80 hd-h70"/><a href='javascript:;' style='color:red' class='del-image'>X中图</a>
			            <input type="hidden" name="mean[]" value="{{$v}}"/>
			            {{endforeach}}
			            {{foreach from="$OlddetailsData['small']" key='$k' value='$v'}}
						<li path="{{$v}}" url="{{$v}}"><img src="{{$v}}" class="hd-w80 hd-h70"/><a href='javascript:;' style='color:red' class='del-image'>X小图</a>
			            <input type="hidden" name="small[]" value="{{$v}}"/>
			            {{endforeach}}
					</td>
				</tr>
			</table>
			<p class="hd-title-header" id="detail">商品详细</p>
			<table class='hd-table hd-table-form'>
				<tr class="hide info">
					<td>
						<script id="ed" type="text/plain" style="width:100%;height:300px;" name="spcontent">{{$OlddetailsData['spcontent']}}</script>
	                    <script>
							var ue = UE.getEditor('ed');
						</script>
					</td>
				</tr>
			</table>
			<p class="hd-title-header" id="service">售后服务</p>
			<table class='table'>
				<tr class="hide info">
					<td>
						<!--<textarea name="service" id="service"></textarea>-->
						<script id="ed1" type="text/plain" style="width:100%;height:300px;" name="service">{{$OlddetailsData['service']}}</script>
	                    <script>
							var ue = UE.getEditor('ed1');
						</script>
					</td>
				</tr>
			</table>

			<input type="submit" value="确认添加" class="hd-btn hd-btn-success" style="height: 40px;"/>
	</form>

	</div>
	</div>
	</div>
</body>
</html>